﻿<?php

	class Utils 
	{
		
		public static function redirect($page)
		{
			header('location: index.php?p='.$page);
		}
		
		public static function redirectLogin()
		{
			header('location: auth.php?p=login');
		}
		
		public static function redirectLogout()
		{
			header('location: auth.php?p=logout');
		}
		
		public static function checkField($f)
		{
			if ( empty($_POST) )
			{
				return true;
			}
			return isset($_POST[$f]) && !empty($_POST[$f]);
		}

		public static function insertErrorCssClass($f)
		{
			if ( !Utils::checkField($f) )
			{
				echo 'class="error"';
			}
		}

		public static function showErrorMessage($msg)
		{
			return '<br/><span class="error">'.$msg.'</span>';
		}
		
		public static function handleFormAction($action, $params)
		{
			switch ($action)
			{
				case 'checklogin':
					Session::checkUserInfo($params);
				break;				
				
				case 'createaccount':
					DB::setUserAccount($params);
				break;

			}
		}
		
		public static function breadCrumbs($menu_items)
		{

			$bc = '
			<div class="breadcrumbs">
				<ul>
					<li><a href="index.php" title="Back to home"><span class="bc_home"></span></a></li>
			';
			
			foreach($menu_items as $item)
			{
				
				$bc .= '<li><span class="bc_arrow"></span></li>';
				
				if ( isset($item['link']) && !empty($item['link']) )
				{
					$item['title'] = isset($item['title']) && !empty($item['title']) ? 
										$item['title'] : 'Back to '.$item['label'];				
					$bc .= '<li><a href="index.php?p='.$item['link'].'" title="'.$item['title'].'"><span class="bc_text">'.$item['label'].'</span></a></li>';
					//$bc .= '<li><span class="bc_arrow"></span></li>';
				} else 
				{
					$bc .= '<li><span class="bc_text">'.$item['label'].'</span></li>';
				}
				
			}
					
			$bc .= '</div>';
			
			return $bc;
			
		}
		
	}
	
?>
